package com.vvv.designpattern.dprecated.state.controller;

import com.vvv.designpattern.dprecated.state.DeprecatedOrder;
import com.vvv.designpattern.dprecated.state.service.DeprecatedOrderService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @author vvv
 * @date 2023-11-20 11 43
 * discription 状态模式 + 观察者模式
 *
 * 这里的业务是：
 * 订单状态转换
 *
 * 流程是：用户发起了请求，请求先到controller，然后到service，
 * 如果service中这个请求执行成功，那么订单的状态就应该改变，
 * 如果订单状态发生改变，就应该去通知服务端（观察者）去做相应的操作
 *
 * 比如：现在订单的状态是待支付状态
 * 1. 用户发起支付的请求
 * 2. 支付成功
 * 3. 订单的状态为：待支付状态 -> 待发货状态
 * 4. 通知服务端发货
 */
@RestController
@RequestMapping("/deprecated/order")
public class DeprecatedOrderController {

    @Resource
    private DeprecatedOrderService deprecatedOrderService;

    @PostMapping("/create")
    public DeprecatedOrder createOrder(@RequestParam String productId) {
        return deprecatedOrderService.createOrder(productId);
    }

    @PostMapping("/pay")
    public DeprecatedOrder payOrder(@RequestParam String orderId) {
        return deprecatedOrderService.pay(orderId);
    }

    @PostMapping("/send")
    public DeprecatedOrder sendOrder(@RequestParam String orderId) {
        return deprecatedOrderService.send(orderId);
    }

    @PostMapping("/receive")
    public DeprecatedOrder receiveOrder(@RequestParam String orderId) {
        return deprecatedOrderService.receive(orderId);
    }
}
